#pragma once

#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <fcntl.h>

#include "Stream.h"
#include "../common/log.hpp"
#include "../common/Utils.hpp"

namespace efs
{
	/** \brief
	 *  Class contains socket and methods to work with it.
	 */
	class Socket2 : public Stream2
	{
	public:

		/**
		 *
		 * @param listener Base socket.
		 */
		Socket2(const int listener);

		virtual ~Socket2();

		/**
		 * Reading data array.
		 * @param data Pointer to array.
		 * @param size Array size.
		 * @return Number of bytes were received.
		 */
		size_t read(char *data, size_t size);

		/**
		 * Writing data array.
		 * @param data Pointer to array.
		 * @param size Array size.
		 * @return Number of bytes were sent.
		 */
		int write(char *data, size_t size);

	private:

		Socket2(Socket2 &);
		Socket2 & operator=(Socket2 &);
		bool waitForEvent(void);

		int m_listener;
		int m_socket;
		int m_receive_timeout;
		int m_transmitt_timeout;
	};
}
